// ============================================================================
// Implementation file for Myxdr
//
// Solution for CPSC 4780 Fall 2010 Group Project
// Fei Wang
// April 8, 2011
//
// ============================================================================
#include "Myxdr.h"
#include <string>
#include <iostream>
#include <sstream>

using namespace std;
// ==========================================================================
// function handle xdr to int and int to xdr conversion
//===========================================================================
bool my_xdr_int(XDR *  xdrs,char * ip ,int xdr_status)
{
   
    if(xdr_status == 1)
    {
        stringstream stream;
        stream << *((int*)ip);
        stream >> *xdrs;
    }
    else if (xdr_status == 2)
    {
        stringstream stream;
        stream << *xdrs;
        stream >> *((int*)ip);
    }
    return true;
}
// ==========================================================================
// function handle xdr to float and float to xdr conversion
//============================================================================
bool my_xdr_float(XDR * xdrs,char * fp ,int xdr_status)
{
    if(xdr_status == 1)
    {
        stringstream stream;
        stream << *((float*)fp);
        stream >> *xdrs;
    }
    else if (xdr_status == 2)
    {
        stringstream stream;
        stream << *xdrs;
        stream >> *((float*)fp);
    }
	return true;
}
// ==========================================================================
// function handle xdr to char and char to xdr conversion
//============================================================================
bool my_xdr_char(XDR * xdrs, char * cp ,int xdr_status)
{
    if(xdr_status == 1)
    {
        stringstream stream;
        stream << *cp;
        stream >> *xdrs;
    }
    else if (xdr_status == 2)
    {   
        stringstream stream;
        stream << *xdrs;
        stream >> *cp;
    }
    return true;
}
